package it.tcon.xbeedriver;

import org.apache.log4j.Logger;

public class TestXBeeDriver {
	
	static XBeeCom xbeecom;
	//static Logger logger = Logger.getLogger(TestXBeeDriver.class);

	public static void main(String args[]) throws InterruptedException{
	
		// Initialize an XBee communication
		xbeecom = new XBeeCom();
		
		// Try to connect to the coordinator
		if(!xbeecom.xbeeConnect("/dev/tty.usbserial-A5001pRJ", 9600)){
			//logger.error("Could not connect to Coordinator");
			System.exit(1);
		}
		//logger.info("Connected to the Coordinator");
		
		// Start the Receiver manager
		xbeecom.xbeeReceiver();
		// Send a Discovery message
		xbeecom.xbeeDiscover();
			
		// Sleep waiting a complete discovery
		// The ATND discovery command on the ZigBee driver don't predict how many nodes are on the networks
		// so a little forced waiting have to be done.
		Thread.currentThread().sleep(6000);
		
		// Save the network information on the node.dat file in XML format
		xbeecom.saveNodeList();
		
		// Print the network configuration.
		//logger.info("Network configuration:\n"+xbeecom.getNodes());
		System.out.println(""+xbeecom.getNodes());
		// Close the connection to the Coordinator
		xbeecom.xbeeDisconnect();
	
  }
}
